package com.open.party.cloud.view.home.juBao.fragment

import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.widget.AppCompatSpinner
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.open.party.cloud.R
import com.open.party.cloud.model.DictionaryBean
import com.open.party.cloud.view.home.juBao.JuBao12380JuBaoClassActivity
import com.open.party.cloud.view.home.juBao.JuBao12380JuBaoShiMingActivity
import com.open.party.cloud.view.home.juBao.JuBaoData
import com.sinothk.android.utils.XUtils
import com.sinothk.switchTabView.style1.UIUtil
import kotlinx.android.synthetic.main.ju_bao_12380_fragment_other_info.*

class JuBaoOtherInfoFragment : Fragment() {


    private var currView: View? = null

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        if (currView == null) {
            currView = inflater.inflate(R.layout.ju_bao_12380_fragment_other_info, container, false)
        }
        return currView
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

        initView()
    }

    private fun initView() {
        if (JuBao12380JuBaoShiMingActivity.class1 == JuBao12380JuBaoClassActivity.JB_CLass_Ge_Ren) {
            // 举报个人
            input01View.visibility = View.VISIBLE
            input02View.visibility = View.VISIBLE
            input03View.visibility = View.VISIBLE
            input04View.visibility = View.VISIBLE
            input05View.visibility = View.VISIBLE
            input05FlagTv.text = "所在单位："

            input06View.visibility = View.VISIBLE
            input07View.visibility = View.VISIBLE
            input08View.visibility = View.VISIBLE
            input09View.visibility = View.VISIBLE
        } else {
            // 举报单位
            input01View.visibility = View.VISIBLE
            input02View.visibility = View.GONE
            input03View.visibility = View.GONE
            input04View.visibility = View.GONE
            input05View.visibility = View.VISIBLE
            input05FlagTv.text = "被举报单位："

            input06View.visibility = View.GONE
            input07View.visibility = View.VISIBLE
            input08View.visibility = View.VISIBLE
            input09View.visibility = View.VISIBLE
        }

        initSpinnerListView()
    }

    private fun initSpinnerListView() {
        input01Et.text = XUtils.string().getNotNullValue(JuBao12380JuBaoShiMingActivity.area)

        initSexListView()
        initLevelListView()
        initQuestionTypeListView()
    }

    //    fun input01Et(): String = areaBeanStr
    fun input02Et(): EditText = input02Et
    fun input03Et(): String = sexStr
    fun input04Et(): EditText = input04Et
    fun input05Et(): EditText = input05Et
    fun input06Et(): EditText = input06Et
    fun input07Et(): String = levelStr
    fun input08Et(): String = questionTypeStr
    fun input09Et(): EditText = input09Et

    //    var areaBeanStr = ""
    var sexStr = ""
    var levelStr = ""
    var questionTypeStr = ""

//    private fun initAreaListView() {
//        val levelBeanList = ArrayList<DictionaryBean>()
//        // {pt:普通;jj:紧急;tj:特急}
//        levelBeanList.add(DictionaryBean("LPSS", "六盘水市"))
//        levelBeanList.add(DictionaryBean("PT", "钟山区"))
//        levelBeanList.add(DictionaryBean("JJ", "六枝特区"))
//        levelBeanList.add(DictionaryBean("TJ", "水城区"))
//        levelBeanList.add(DictionaryBean("TJ", "盘州市"))
//
//        val levelValueList = ArrayList<String>()
//        for (areaBean in levelBeanList) {
//            levelValueList.add(areaBean.desc)
//        }
//
//        initSpinnerView(areaSpinner, levelValueList, object : AdapterView.OnItemSelectedListener {
//            override fun onNothingSelected(parent: AdapterView<*>?) {
//            }
//
//            override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
//
//                if (view != null) {
//                    val tv = view as TextView
//                    tv.setTextColor(ContextCompat.getColor(activity!!, R.color.page_content))
//                    tv.paint.textSize = UIUtil.sp2px(activity!!, 14f).toFloat()
//                    tv.gravity = Gravity.START
//                    areaBeanStr = levelBeanList[position].desc
//                }
//            }
//        })
//    }

    private fun initSexListView() {

        val valueList = JuBaoData.getSexList()

        val valueStrList = ArrayList<String>()
        for (areaBean in valueList) {
            valueStrList.add(areaBean.desc)
        }

        initSpinnerView(sexSpinner, valueStrList, object : AdapterView.OnItemSelectedListener {
            override fun onNothingSelected(parent: AdapterView<*>?) {
            }

            override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {

                if (view != null) {
                    val tv = view as TextView
                    tv.setTextColor(ContextCompat.getColor(activity!!, R.color.page_content))
                    tv.paint.textSize = UIUtil.sp2px(activity!!, 14f).toFloat()
                    tv.gravity = Gravity.START
                    sexStr = valueList[position].desc
                }
            }
        })
    }

    private fun initLevelListView() {

        val valueList = JuBaoData.getLevelList()

        val valueStrList = ArrayList<String>()
        for (areaBean in valueList) {
            valueStrList.add(areaBean.desc)
        }

        initSpinnerView(levelSpinner, valueStrList, object : AdapterView.OnItemSelectedListener {
            override fun onNothingSelected(parent: AdapterView<*>?) {
            }

            override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {

                if (view != null) {
                    val tv = view as TextView
                    tv.setTextColor(ContextCompat.getColor(activity!!, R.color.page_content))
                    tv.paint.textSize = UIUtil.sp2px(activity!!, 14f).toFloat()
                    tv.gravity = Gravity.START
                    levelStr = valueList[position].desc
                }
            }
        })
    }

    private fun initQuestionTypeListView() {// 问题类型
        val valueList = JuBaoData.getQuestionTypeList()

        val valueStrList = ArrayList<String>()
        for (areaBean in valueList) {
            valueStrList.add(areaBean.desc)
        }

        initSpinnerView(questionTypeSpinner, valueStrList, object : AdapterView.OnItemSelectedListener {
            override fun onNothingSelected(parent: AdapterView<*>?) {
            }

            override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {

                if (view != null) {
                    val tv = view as TextView
                    tv.setTextColor(ContextCompat.getColor(activity!!, R.color.page_content))
                    tv.paint.textSize = UIUtil.sp2px(activity!!, 14f).toFloat()
                    tv.gravity = Gravity.START
                    questionTypeStr = valueList[position].desc
                }
            }
        })
    }

    private var spinnerAdapter: ArrayAdapter<String>? = null

    private fun initSpinnerView(
        spinner: AppCompatSpinner, streetStrList: ArrayList<String>, itemSelectedListener: AdapterView.OnItemSelectedListener?
    ) {
        spinnerAdapter = ArrayAdapter(activity!!, R.layout.street_spinner_item, streetStrList!!)
        spinnerAdapter!!.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.adapter = spinnerAdapter
        spinner.dropDownVerticalOffset = 100

        spinner.onItemSelectedListener = itemSelectedListener
    }
}